package ink.teamwork.sys.service.impl;

import com.googlecode.genericdao.search.Search;
import com.googlecode.genericdao.search.SearchResult;
import ink.teamwork.sys.dao.SysUserDAO;
import ink.teamwork.sys.entity.SysUser;
import ink.teamwork.sys.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    public SysUserDAO sysUserDAO;

    @Override
    public SysUser queryById(Long id) {
        return sysUserDAO.find(id);
    }

    @Override
    public Boolean saveOrUpdate(SysUser user) {
        return sysUserDAO.save(user);
    }

    @Override
    public SearchResult<SysUser> queryPage(int start, int size) {
        Search search = new Search();
        search.setFirstResult(start);
        search.setMaxResults(size);
        search.addSortDesc("id");
        return null;
    }

    @Override
    public SysUser queryByEmail(String email) {
        Search search = new Search();
        search.addFilterEqual("email", email);
        return sysUserDAO.searchUnique(search);
    }

    @Override
    public List<SysUser> listAll() {
        return sysUserDAO.findAll();
    }
}
